﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VoirEspaceDisk
{
    public partial class RegleRecherche : Form
    {
        // indique s'il y a une borne (inférieure ou supérieure) ou un intervalle
        public int NombreBornes { get; private set; }
        public long Borne1 { get; private set; }
        public long Borne2 { get; private set; }

        public RegleRecherche()
        {
            InitializeComponent();
            labelEt.Visible = false;
            numericUpDown2.Visible = false;
            comboBoxTaille2.Visible = false;
            comboBoxTypeRecherche.SelectedIndex = 0;
            comboBoxTaille1.SelectedIndex = 2;
            comboBoxTaille2.SelectedIndex = 2;
        }

        private void comboBoxTypeRecherche_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBoxTypeRecherche.SelectedIndex)
            {
                case 0: // supérieur
                    labelEt.Visible = false;
                    numericUpDown2.Visible = false;
                    comboBoxTaille2.Visible = false;
                    labelAouEntre.Text = "à";
                    break;
                case 1: //inférieur
                    labelEt.Visible = false;
                    numericUpDown2.Visible = false;
                    comboBoxTaille2.Visible = false;
                    labelAouEntre.Text = "à";
                    break;
                case 2: // compris
                    labelEt.Visible = true;
                    numericUpDown2.Visible = true;
                    comboBoxTaille2.Visible = true;
                    labelAouEntre.Text = "entre";
                    break;
                default:
                    break;
            }
        }

        private void buttonValider_Click(object sender, EventArgs e)
        {
            if (comboBoxTypeRecherche.SelectedIndex == 2)
            {
                NombreBornes = 2;
                Borne1 = (long)(numericUpDown1.Value * (decimal)Math.Pow(10D, (double)comboBoxTaille1.SelectedIndex));
                Borne2 = (long)(numericUpDown2.Value * (decimal)Math.Pow(10D, (double)comboBoxTaille2.SelectedIndex));
            }
            else
            {
                NombreBornes = 1;
                Borne1 = (long)(numericUpDown1.Value * (decimal)Math.Pow(1000D, (double)(comboBoxTaille1.SelectedIndex)));
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void buttonAnnuler_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
    }
}
